//
//  AudioSessionManager.swift
//  MyVideo
//
//  Created by han on 2021/4/25.
//

import AVFoundation

class AudioSessionManager {
    static let shared: AudioSessionManager = AudioSessionManager()
    
    private init() {}
    
    private var audioSessionObserver: Any!
    
    func start() {
        audioSessionObserver = NotificationCenter.default.addObserver(forName: AVAudioSession.mediaServicesWereResetNotification, object: nil, queue: nil, using: { (notification) in
            self.setUpAudioSession()
        })
        setUpAudioSession()
    }
    // LongForm
    private func setUpAudioSession() {
        do {
            try  AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, policy: .longFormAudio)
        } catch {
            print("Failed to set audio session route sharing policy: \(error)")
        }
    }
}

// appdelegate中开启
// AudioSessionManager.shared.start()
